﻿using System;
using FireStarterModeller.BO;
using FireStarterModeller.UI.LookupLists;
using Habanero.Faces.Base;
using Habanero.Faces.Win;
using NUnit.Framework;

namespace FireStarterModeller.Test.UI.LookupLists
{
    [TestFixture]
    public class TestNoneLookupListControl
    {
        // For The NoneLookupTypeControl:
        //  - The DMProperty will just act as a prop
        //  - The LookupList will always return null
        //  - The control will only contain a label saying like: "Please select a lookup list type....." look at old FS

        [TestFixtureSetUp]
        public void SetupFixture()
        {
            UITestUtils.SetupFixture();
        }

        [SetUp]
        public virtual void SetupTest()
        {
            UITestUtils.SetupTest();
        }

        private static IControlFactory CreateControlFactory()
        {
            return new ControlFactoryWin();
        }

        //Constructor should create label with text "Please select a look type."
        [Test]
        public void Test_Construct()
        {
            //---------------Set up test pack-------------------
            IControlFactory controlFactory = CreateControlFactory();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            NoneLookupListControl noneLookupListControl = new NoneLookupListControl(controlFactory);
            //---------------Test Result -----------------------
            Assert.AreSame(controlFactory, noneLookupListControl.ControlFactory);
            Assert.AreEqual(1, noneLookupListControl.Controls.Count);
            Assert.IsInstanceOf(typeof (ILabel), noneLookupListControl.Controls[0]);
            Assert.AreEqual("Please select a lookup list type.", noneLookupListControl.Controls[0].Text);
        }

        [Test]
        public void Test_WhenNullControlFactorySet_ShouldThrowException()
        {
            //---------------Set up test pack-------------------
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            try
            {
                NoneLookupListControl noneLookupListControl = new NoneLookupListControl(null);
                Assert.Fail("expected ArgumentNullException");
            }
                //---------------Test Result -----------------------
            catch (ArgumentNullException ex)
            {
                StringAssert.Contains("Value cannot be null", ex.Message);
                StringAssert.Contains("controlFactory", ex.ParamName);
            }
            //---------------Test Result -----------------------
        }

        [Test]
        public void Test_NoneLookupListControl_IsILookupTypeControl()
        {
            //---------------Set up test pack-------------------
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            NoneLookupListControl noneLookupListControl = new NoneLookupListControl(CreateControlFactory());
            //---------------Test Result -----------------------
            Assert.IsInstanceOf(typeof(ILookupListControl),noneLookupListControl);
        }

        [Test]
        public void Test_LookupTypeName_ShouldReturn_NoneLookup()
        {
            //---------------Set up test pack-------------------
            NoneLookupListControl noneLookupListControl = new NoneLookupListControl(CreateControlFactory());
            const string actual = "None";
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            string lookupTypeName = noneLookupListControl.LookupTypeName;
            //---------------Test Result -----------------------
            Assert.AreEqual(lookupTypeName,actual);
        }

        [Test]
        public void Test_LookupList_ShouldAlwaysReturnNull()
        {
            //---------------Set up test pack-------------------
            NoneLookupListControl noneLookupListControl = new NoneLookupListControl(CreateControlFactory());
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMLookupList lookupList = noneLookupListControl.LookupList;
            //---------------Test Result -----------------------
            Assert.IsNull(lookupList);
        }

        [Test]
        public void Test_DMProperty_GetAndSet()
        {
            //---------------Set up test pack-------------------
            NoneLookupListControl noneLookupListControl = new NoneLookupListControl(CreateControlFactory());
            DMProperty dmProperty = TestUtilsDMProperty.CreateUnsavedValidDMProperty();
            //---------------Assert Precondition----------------
            Assert.IsNull(noneLookupListControl.Property);
            //---------------Execute Test ----------------------
            noneLookupListControl.Property = dmProperty;
            //---------------Test Result -----------------------
            Assert.IsNotNull(noneLookupListControl.Property);
            Assert.AreEqual(dmProperty,noneLookupListControl.Property);
        }
    }
}
